﻿using System;
using full_leaf_framework.Interact;
using full_leaf_framework.Visual;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace input_manager;

public class Game1 : Game {
    private GraphicsDeviceManager _graphics;
    private SpriteBatch _spriteBatch;

    private const int SCREEN_WIDTH = 800;
    private const int SCREEN_HEIGHT = 600;

    public InputManager inputManager;
    public Camera camera;

    public Game1() {
        _graphics = new GraphicsDeviceManager(this)
        {
            PreferredBackBufferWidth = SCREEN_WIDTH,
            PreferredBackBufferHeight = SCREEN_HEIGHT
        };
        _graphics.ApplyChanges();
        Content.RootDirectory = "Content";
        IsMouseVisible = true;
    }

    protected override void Initialize() {
        base.Initialize();
        inputManager = new InputManager();
        inputManager.InsertTrackingKeys(new Keys[4] {Keys.W, Keys.A, Keys.S, Keys.D});
    }

    protected override void LoadContent() {
        _spriteBatch = new SpriteBatch(GraphicsDevice);
        camera = new Camera(_spriteBatch, new Rectangle(0, 0, 800, 600), new Vector2(0, 0), new Vector2(800, 600));
    }

    protected override void Update(GameTime gameTime) {
        base.Update(gameTime);
        var keyA = inputManager.GetTrackingKey(Keys.A);
        if (keyA.fired) { Console.WriteLine("fired"); }
        if (keyA.pressed) { Console.WriteLine("pressed"); }
        if (keyA.released) { Console.WriteLine("released"); }
        if (keyA.holdTime > 1f) { Console.WriteLine("Long Pressed"); }
        var mouse = inputManager.GetTrackingMouse();
        if (mouse.firedLeft) { Console.WriteLine(mouse.pos.X + ", " + mouse.pos.Y); }
        var actualPos = camera.ReturnPointerPos(mouse.pos.ToVector2());
    }

    protected override void Draw(GameTime gameTime) {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        base.Draw(gameTime);
    }
}
